package com.tanhua.server.controller;

import com.tanhua.server.service.IMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@RestController
@RequestMapping("/messages")
public class IMController {

    @Autowired
    private IMService imService;

    @PostMapping("/contacts")
    public ResponseEntity<Object> addContacts(@RequestBody Map<String,Object> params){
        Integer userId = (Integer) params.get("userId");
        return imService.addContacts(userId);
    }

    @GetMapping("/contacts")
    public ResponseEntity<Object> showContacts(@RequestParam(defaultValue = "1")Integer page,
                                               @RequestParam(defaultValue = "10")Integer pagesize,
                                               String keyword) throws InvocationTargetException, IllegalAccessException {
        return imService.showContacts(page,pagesize,keyword);
    }

    @GetMapping("/likes")
    public ResponseEntity<Object> likeList(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize) throws InvocationTargetException, IllegalAccessException {
        return imService.getList(page,pagesize,1);
    }

    @GetMapping("/comments")
    public ResponseEntity<Object> commentList(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize) throws InvocationTargetException, IllegalAccessException {
        return imService.getList(page,pagesize,2);
    }

    @GetMapping("/loves")
    public ResponseEntity<Object> loveList(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pagesize) throws InvocationTargetException, IllegalAccessException {
        return imService.getList(page,pagesize,3);
    }

}

